package com.vcms.view.simulation.uicomponent.display;

/**
 * Title:        VMCS
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      ISS
 * @author Pang Pingli
 * @version 1.0
 */
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Panel;

import com.vcms.controller.maintenance.MaintenanceController;
import com.vcms.controller.storemanagement.StoreController;
import com.vcms.entity.store.item.StoreItem;
import com.vcms.exception.VMCSException;
import com.vcms.view.simulation.uicomponent.button.ButtonItemDisplay;
import com.vcms.view.simulation.uicomponent.listener.DrinkDisplayListener;
import com.vcms.view.simulation.uicomponent.listener.PriceDisplayListener;

@SuppressWarnings("serial")
public class DrinkDisplay extends Panel {

	public final static String TITLE = "Quantity of Drinks Available";

	private StoreController storeCtrl;
	private MaintenanceController mCtrl;
	private ButtonItemDisplay bi;
	private LabelledDisplay price;
	private int curIdx = -1; // current displayed item index;

	public DrinkDisplay(MaintenanceController mctrl) {
		mCtrl = mctrl;
		storeCtrl = mCtrl.getMainController().getStoreController();

		this.setLayout(new BorderLayout());
		int len;
		len = storeCtrl.getStoreSize(StoreController.DRINK);
		StoreItem[] items = storeCtrl.getStoreItems(StoreController.DRINK);

		bi = new ButtonItemDisplay(TITLE, items, len);

		bi.addListener(new DrinkDisplayListener(mCtrl));
		bi.clear();
		price = new LabelledDisplay("Brand Price", 4, LabelledDisplay.FLOW);

		PriceDisplayListener pdl;

		pdl = new PriceDisplayListener(mCtrl);
		price.addListener(pdl);
		Panel tp = new Panel();
		tp.setLayout(new FlowLayout(FlowLayout.CENTER));
		tp.add(bi);
		curIdx = 0;
		this.add("Center", tp);
		this.add("South", (Panel)price.getLabelledDisplay());
		price.getLabelledDisplay().setEnabled(false);
	}

	public LabelledDisplay getPriceDisplay() {
		return price;
	}

	public void setActive(boolean st) {
		price.setActive(st);
		bi.setActive(st);
	}

	public void displayQty(int idx, int qty) throws VMCSException {
		curIdx = idx;
		bi.clear();
		price.getLabelledDisplay().setEnabled(true);
		bi.displayQty(idx, qty);
	}

	public int getCurIdx() {
		return curIdx;
	}

}